<?php

class Game
{
    private $_players = array();
    private $_dice = null;
    private $_board = null;
    private $_round_count = 0;

    public function __construct($dice, $board, $players)
    {
        if (count($players) < 2 || count($players) > 8) {
            throw new Exception("Monopoly must be played by 2 to 8 players");
        }

        $this->setDice($dice);
        $this->setBoard($board);
        $this->setPlayers($players);        
    }

    public function setPlayers($players)
    {
        shuffle($players);
        $this->_players = $players;
    }

    public function getPlayers()
    {
        return $this->_players;
    }

    public function setDice($dice)
    {
        $this->_dice = $dice;
    }

    public function getDice()
    {
        return $this->_dice;
    }

    public function setBoard($board)
    {
        $this->_board = $board;
    }

    public function getBoard()
    {
        return $this->_board;
    }

    public function incrementRoundsPlayed()
    {
        $rounds_played = $this->getRoundsPlayed();
        $this->setRoundsPlayed($rounds_played + 1);
    }

    public function setRoundsPlayed($rounds_played)
    {
        $this->_round_count = $rounds_played;
    }

    public function getRoundsPlayed()
    {
        return $this->_round_count;
    }

    public function playRound()
    {
        foreach ($this->getPlayers() as $player) {
            $dice = $this->getDice();
            $player->takeTurn($dice);
        }

        $this->incrementRoundsPlayed();
    }
}
